asm
  ld sp,$47FF
  end asm

#include "./library/smsrnd.bas"

dim dly as uinteger at $4010
dim eee as uinteger at $4012
dim seed as uinteger at $4014
dim ee2 as uinteger at $4016
dim ee3 as uinteger at $4018
dim ee4 as ubyte at $401A
dim ecsp as ubyte at $401C
dim ecsq as ubyte at $401E
dim ex0 as uinteger at $4020
dim ey0 as uinteger at $4022
dim ej0 as uinteger at $4024
dim ej1 as uinteger at $4026
dim i as uinteger at $4028

'-------------------------

sub scrambleputsprite(tlayer as ubyte,tx as ubyte,ty as ubyte,tid as ubyte,tclut as ubyte):
  poke $5040+((tlayer band 7)*4),tx     '- x sprite 0   '- band 7?
  poke $5041+((tlayer band 7)*4),tid    '- shape sprite 0
  poke $5042+((tlayer band 7)*4),tclut  '- clut? sprite 0
  poke $5043+((tlayer band 7)*4),ty     '- y sprite 0
  end sub

sub scrambleputchar(tx1 as uinteger, ty1 as uinteger, tch1 as uinteger)
  poke ($4800+(tx1*32)+ty1) bxor %0000001111100000,(tch1 band 255)
  end sub

sub scramblescroll(ty1 as uinteger, tx1 as uinteger)
  poke $5000+((ty1 band 31)*2),tx1
  end sub

sub scrambleattr(ty1 as uinteger, tx1 as uinteger)
  poke $5001+((ty1 band 31)*2),tx1
  end sub

'-------------------------

seed=0

'background
for eee=$4800 to $4BFF
  poke eee,code("-")
  next

'colourattribute
for eee=0 to 31
  for dly=1 to 1000:next
  seed=smsrnd(seed)
  scrambleattr(eee,seed)
  next

' background again
for ee3=0 to 31
  for ee2=8 to 31
    for dly=1 to 100:next
    scrambleputchar(ee2,ee3,code("."))
    next:next

'scroll
for eee=0 to 31
  for dly=1 to 1000:next
  seed=smsrnd(seed)
  scramblescroll(eee,seed)
  next

'- sprites
for eee=$5040 to $505F
  'for dly=1 to 10000:next
  seed=smsrnd(seed)
  poke eee,seed
  next

'- unknown
for eee=$5060 to $507F
  for dly=1 to 100:next
  seed=smsrnd(seed)
  poke eee,seed
  next

'scroll again
for eee=$5000 to $503F step 2
  for dly=1 to 1000:next
  poke eee,0
  next

'-ascii
ee4=0
for ee3=12 to 12+15
  for ee2=12 to 12+15
    poke ($4800+(ee2*32)+ee3) bxor %0000001111100000,ee4
    ee4=ee4+1
    next:next

'- sprites
for eee=0 to 255
  for dly=1 to 100:next
  scrambleputsprite(0,eee,128,0,0)
  scrambleputsprite(1,eee+16,128,0,0)
  scrambleputsprite(2,eee+32,128,0,0)
  scrambleputsprite(3,eee+48,128,0,0)
  scrambleputsprite(4,eee,128+16,0,0)
  scrambleputsprite(5,eee+16,128+16,0,0)
  scrambleputsprite(6,eee+32,128+16,0,0)
  scrambleputsprite(7,eee+48,128+16,0,0)

  'poke $5040,eee  '- $5040 to $505F
  next
scrambleputsprite(0,128,128,0,0)

for ee2=0 to 11
  scrambleputchar(12+ee2,10,peek(@text01+ee2))
  next

ex0=128:ey0=128:eee=0

do
  seed=smsrnd(seed)
  for ee2=1 to 1000:next
  'poke $5004,eee
  'eee=(eee+1) band 255

  ej0=peek($8100) bxor 255
  ej1=peek($8101) bxor 255

  poke ($4800+(6*32)+20) bxor %0000001111100000,ej0
  poke ($4800+(7*32)+20) bxor %0000001111100000,ej1

  poke ($4800+(8*32)+25) bxor %0000001111100000,48+(ej0 mod 10)
  poke ($4800+(7*32)+25) bxor %0000001111100000,48+((int(ej0/10)) mod 10)
  poke ($4800+(6*32)+25) bxor %0000001111100000,48+((int(ej0/100)) mod 10)

  poke ($4800+(8*32)+26) bxor %0000001111100000,48+(ej1 mod 10)
  poke ($4800+(7*32)+26) bxor %0000001111100000,48+((int(ej1/10)) mod 10)
  poke ($4800+(6*32)+26) bxor %0000001111100000,48+((int(ej1/100)) mod 10)

  poke ($4800+(8*32)+22) bxor %0000001111100000,48+(ex0 mod 10)
  poke ($4800+(7*32)+22) bxor %0000001111100000,48+((int(ex0/10)) mod 10)
  poke ($4800+(6*32)+22) bxor %0000001111100000,48+((int(ex0/100)) mod 10)

  poke ($4800+(8*32)+23) bxor %0000001111100000,48+(ey0 mod 10)
  poke ($4800+(7*32)+23) bxor %0000001111100000,48+((int(ey0/10)) mod 10)
  poke ($4800+(6*32)+23) bxor %0000001111100000,48+((int(ey0/100)) mod 10)

  poke ($4800+(8*32)+24) bxor %0000001111100000,48+(eee mod 10)
  poke ($4800+(7*32)+24) bxor %0000001111100000,48+((int(eee/10)) mod 10)
  poke ($4800+(6*32)+24) bxor %0000001111100000,48+((int(eee/100)) mod 10)
  poke ($4800+(5*32)+24) bxor %0000001111100000,48+((int(eee/1000)) mod 10)
  poke ($4800+(4*32)+24) bxor %0000001111100000,48+((int(eee/10000)) mod 10)

  ex0=ex0+((ej0 band 16)/16)
  ex0=ex0-((ej0 band 32)/32)
  ey0=ey0+((ej1 band 16)/16)
  ey0=ey0-((ej1 band 32)/32)

  scrambleputsprite(0,ex0,ey0,0,0)
  scrambleputsprite(1,ex0+16,ey0,0,0)
  scrambleputsprite(2,ex0+32,ey0,0,0)
  scrambleputsprite(3,ex0+48,ey0,0,0)
  scrambleputsprite(4,ex0,ey0+16,0,0)
  scrambleputsprite(5,ex0+16,ey0+16,0,0)
  scrambleputsprite(6,ex0+32,ey0+16,0,0)
  scrambleputsprite(7,ex0+48,ey0+16,0,0)

  scrambleattr( ((ey0 mod 12)+29) band 31,seed)
  scramblescroll( ((ey0 mod 12)+29) band 31,ex0)

  loop

'-------------------------------------------------------------------------------

do:loop

text01:
asm
  defb "HELLO WORLD!!!!!"
  end asm

'-------------------------------------------------------------------------------

